'use strict';
//////////////////////////////////////////////////////////////////////////////
// 信息提示
// 挺漂亮的文本弹窗
// =====================
// liuyp 2018年11月28日15: 30: 04
//////////////////////////////////////////////////////////////////////////////
function $notify() {
    function n(n, t) {
        for (var property in t) t.hasOwnProperty(property) && (n[property] = t[property]); return n
    }
    function t(n, t, delay, op, func) {
        var i = document.createElement("div"); i.className = "notyf";
        var e = document.createElement("div"); e.className = "notyf-wrapper";
        var o = document.createElement("div"); o.className = "notyf-icon";
        var a = document.createElement("i"); a.className = t;
        var r = document.createElement("div"); r.className = "notyf-message"; r.innerHTML = n;
        if(op){
            var opBtn = document.createElement("a"); opBtn.href = 'javascript:void(0)';
            opBtn.onclick = function(){ func(close) }; opBtn.innerHTML = op;
            r.appendChild(opBtn)
        }
        o.appendChild(a), e.appendChild(o), e.appendChild(r), i.appendChild(e);
        var c = this;
        function close() {
            i.className += " disappear",
            i.addEventListener(c.animationEnd,
            function(n) { n.target == i && c.container.removeChild(i) });
            var n = c.notifications.indexOf(i);
            c.notifications.splice(n, 1)
        }
        return setTimeout(close, delay||10e3),i
    }
    function i() {
        var n, t = document.createElement("fake"),
        i = {
            transition: "animationend",
            OTransition: "oAnimationEnd",
            MozTransition: "animationend",
            WebkitTransition: "webkitAnimationEnd"
        };
        for (n in i) if (void 0 !== t.style[n]) return i[n]
    }
    function Notyf() {
        this.notifications = [];
        var e = document.createDocumentFragment(),
        o = document.createElement("div");
        o.className = "notyf-container",
        e.appendChild(o),
        document.body.appendChild(e),
        this.container = o,
        this.animationEnd = i()
    }
    function _Dom_prependChild(newEl, parentEl) {
        var r = parentEl.firstChild;
        return r && r.nodeType ? void parentEl.insertBefore(newEl, r) : void parentEl.appendChild(newEl)
    }
    Notyf.prototype.error = function(n, delay) {
        var i = t.call(this, n, "notyf-alert-icon", delay);
        i.className += " alert";
        _Dom_prependChild(i, this.container);
        this.notifications.push(i);
    };
    Notyf.prototype.success = function(n, delay) {
        var i = t.call(this, n, "notyf-confirm-icon", delay);
        i.className += " confirm";
        _Dom_prependChild(i, this.container);
        this.notifications.push(i);
    };
    Notyf.prototype.oprate = function(n, func) {
        var i = t.call(this, n, "notyf-confirm-icon", 30e3 , ' 点击恢复', func);
        i.className += " confirm";
        _Dom_prependChild(i, this.container);
        this.notifications.push(i);
    };
    Notyf.prototype.clear = function() {
        document.querySelectorAll('div.notyf-container').innerHTML = ''
    };
    var notyf = new Notyf();
    window.onerror = function (message, url, line, column, error) {
        console.log('错误监听机制生效了')
        notyf.alert(message);
    }
    return notyf;
};
exports = module.exports = $notify;